import { getCookies } from "utils/cookies";

export default function({ isHMR, app, store, route, params, error, redirect }) {
  const defaultLocale = app.i18n.fallbackLocale;
  // If middleware is called from hot module replacement, ignore it
  if (isHMR) {
    return;
  }
  // Get locale from params
  let locale = getCookies("LNG") || defaultLocale;
  // 如果不存在这种语言类型，那么就设置为默认的语言类型
  if (!store.state.locales.includes(locale)) {
    locale = defaultLocale;
  }
  // Set locale
  store.commit("s_locale", locale);
  app.i18n.locale = store.state.locale;
}
